﻿@{
    ViewBag.Title = "供应商添加";
    //var salerList = ViewBag.SalerList as IEnumerable<CubicFWNet.Data.Models.User>;
}

<section class="content-header">
    <h1>
        供应商添加
    </h1>
    <ol class="breadcrumb">
        <li><a href="javascript:void(0);"><i class="fa fa-dashboard"></i>@Resources.Global.PageTitle</a></li>
        <li><a href="@Url.Action("Index","Home")">首页</a></li>
        <li class="active">供应商添加</li>
    </ol>
</section>

<section class="content">
    <form class="form-horizontal" method="post" id="formMain">
        <div class="box box-solid">
            <div class="box-body">
                <div class="row">

                    <div class="form-group col-md-6 col-sm-12">
                        <label for="Name" class="col-sm-3 control-label">供应商名称</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="Name" name="Name" maxlength="100">
                        </div>
                    </div>

                    <div class="form-group col-md-6 col-sm-12">
                        <label for="ShortName" class="col-sm-3 control-label">供应商简称</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="ShortName" name="ShortName" maxlength="50">
                        </div>
                    </div>

                    @*<div class="form-group col-md-6 col-sm-12">
                            <label for="Type" class="col-sm-3 control-label">客户市场</label>
                            <div class="col-sm-9">
                                <select class="form-control" id="Type" name="Type">
                                    <option value="1"></option>
                                    <option value="2"></option>
                                </select>
                            </div>
                        </div>*@

                    @*<div class="form-group col-md-6 col-sm-12">
                            <input type="hidden" name="SalerName" id="SalerName" />
                            <label for="Saler" class="col-sm-3 control-label">我方销售员</label>
                            <div class="col-sm-9">
                                <select class="form-control" id="Saler" name="Saler">
                                    @if (null != salerList)
                                    {
                                        foreach (var item in salerList)
                                        {
                                            <option value="@item.Id">@item.RealName</option>
                                        }
                                    }
                                </select>
                            </div>
                        </div>*@


                    <div class="form-group col-md-6 col-sm-12">
                        <input type="hidden" name="SalerName" id="SalerName" />
                        <label class="col-sm-3 control-label">采购员</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" value="@ViewBag.RealName" readonly />
                        </div>
                    </div>

                    <div class="form-group col-md-6 col-sm-12">
                        <label for="Address" class="col-sm-3 control-label">供应商地址</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="Address" name="Address" />
                        </div>
                    </div>

                    <div class="form-group col-md-6 col-sm-12">
                        <label for="Corporation" class="col-sm-3 control-label">法人</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="Corporation" name="Corporation" />
                        </div>
                    </div>

                    <!--json数据-->
                    <input style="display:none" id="Data" name="Data" />
                    <div id="json-content">

                        <div class="form-group col-md-6 col-sm-12">
                            <label for="SH" class="col-sm-3 control-label">联系电话</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" id="SH" name="SH" data-des="联系电话" />
                            </div>
                        </div>

                        <div class="form-group col-md-6 col-sm-12">
                            <label for="XS" class="col-sm-3 control-label">销售负责人</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" id="XS" name="XS" data-des="销售负责人" />
                            </div>
                        </div>

                        <div class="form-group col-md-6 col-sm-12">
                            <label for="SY" class="col-sm-3 control-label">邮件</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" id="SY" name="SY" data-des="邮件" />
                            </div>
                        </div>

                        <div class="form-group col-md-6 col-sm-12">
                            <label for="SJ" class="col-sm-3 control-label">设计人</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" id="SJ" name="SJ" data-des="设计人" />
                            </div>
                        </div>

                        <div class="form-group col-md-6 col-sm-12">
                            <label for="CG" class="col-sm-3 control-label">采购负责人</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" id="CG" name="CG" data-des="采购负责人" />
                            </div>
                        </div>

                        <div class="form-group col-md-6 col-sm-12">
                            <label for="DZ" class="col-sm-3 control-label">对账负责人</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" id="DZ" name="DZ" data-des="对账负责人" />
                            </div>
                        </div>

                        <div class="form-group col-md-6 col-sm-12">
                            <label for="ZL" class="col-sm-3 control-label">质量负责人</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" id="ZL" name="ZL" data-des="质量负责人" />
                            </div>
                        </div>

                        <div class="form-group col-md-6 col-sm-12">
                            <label for="CW" class="col-sm-3 control-label">财务负责人</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" id="CW" name="CW" data-des="财务负责人" />
                            </div>
                        </div>
                    </div>

                    <div class="form-group col-md-6 col-sm-12">
                        <label for="Products" class="col-sm-3 control-label">主导产品</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="Products" name="Products" />
                        </div>
                    </div>

                    <div class="form-group col-md-6 col-sm-12">
                        <label for="Yield" class="col-sm-3 control-label">产量</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="Yield" name="Yield" value="0" required/>
                        </div>
                    </div>

                    <div class="form-group col-md-6 col-sm-12">
                        <label for="Range" class="col-sm-3 control-label">应用范围</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="Range" name="Range" />
                        </div>
                    </div>

                    <div class="form-group col-md-6 col-sm-12">
                        <label for="AccountPeriod" class="col-sm-3 control-label">账期</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="AccountPeriod" name="AccountPeriod" />
                        </div>
                    </div>

                    <div class="form-group col-md-6 col-sm-12">
                        <label for="BillingFlow" class="col-sm-3 control-label">开票流程</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="BillingFlow" name="BillingFlow" />
                        </div>
                    </div>

                    <div class="form-group col-md-6 col-sm-12">
                        <label for="StatementDate" class="col-sm-3 control-label">对账日期期限</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="StatementDate" name="StatementDate" />
                        </div>
                    </div>

                    <div class="form-group col-md-6 col-sm-12">
                        <label for="StatementCount" class="col-sm-3 control-label">每月对账次数及流程</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="StatementCount" name="StatementCount" />
                        </div>
                    </div>

                </div>

                <div class="row">
                    <div class="form-group col-md-6 col-sm-12">
                        <label for="Memo" class="col-sm-3 control-label">备注</label>
                        <div class="col-sm-9">
                            <textarea rows="3" class="form-control" id="Memo" name="Memo"></textarea>
                        </div>
                    </div>
                </div>

                <div class="row">
                    <div class="form-group col-md-6 col-sm-12">
                        <label for="Creator" class="col-sm-3 control-label">创建人</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="Creator" name="Tolerance" value="@ViewBag.RealName" readonly="readonly" />
                        </div>
                    </div>
                    <div class="form-group col-md-6 col-sm-12">
                        <label for="CreateTime" class="col-sm-3 control-label">创建时间</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="CreateTime" value="@DateTime.Now.ToString("yyyy-MM-dd HH:mm")" readonly="readonly" />
                        </div>
                    </div>
                </div>

            </div>
            <div class="box-footer">
                <div class="box-footer">
                    <span class="btn btn-primary " onclick="FormSub()">确 定</span>&nbsp;&nbsp;&nbsp;&nbsp;
                    <a class="btn btn-primary" href="@Url.Action("SupplierList","Supplier")">返 回</a>
                </div>
            </div>
        </div>
    </form>
</section>

@section Scripts {
    <script>
        //日期控件
        //$(".Timedatepicker").datepicker({
        //    autoclose: true,
        //    language: 'zh', //汉化
        //    format: "yyyy-mm-dd", //选择日期后，文本框显示的日期格式
        //    minView: "month"//选择日期后，不会再跳转去选择时分秒
        //});

        //获取Json数据
        function getParam() {
            var postdata = [];
            //主键
            $("#json-content").find('input,select,textarea').each(function (r) {
                var $this = $(this);
                var id = $this.attr('id');
                var type = $this.attr('type');
                if (id) {
                    switch (type) {
                        case "checkbox":
                            postdata.push({ des: $this.attr("data-des"), name: id, value: $this.is(":checked") });
                            break;
                        case "select":
                            var value = $this.find("option:selected").val() == "" ? null : $this.find("option:selected").val();
                            postdata.push({ des: $this.attr("data-des"), name: id, value: value });
                            break;
                        default:
                            var value = $this.val() == "" ? "&nbsp;" : $this.val();
                            postdata.push({ des: $this.attr("data-des"), name: id, value: value });
                            break;
                    }
                }
            });
            return JSON.stringify(postdata);
        }

        //提交表单
        function FormSub() {
            var name = $("#Name").val().trim();
            if (name == "") {
                $.modalAlert("请输入名称", "warning");
                return false;
            }

            var shortName = $("#ShortName").val().trim();
            if (shortName == "") {
                $.modalAlert("请输入简称", "warning");
                return false;
            }

            var yield1 = $("#Yield").val().trim();
            if (yield1 == "") {
                $.modalAlert("请输入产量", "warning");
                return false;
            }
            
            //var sal = $("#Saler").val();
            //if (null == sal || sal == "") {
            //    $.modalAlert("请选择我方销售员", "warning");
            //    return false;
            //}

            //下拉列表值
            //$("#SalerName").val($("#Saler").find("option:selected").text());

            //json数据
            var data = getParam();
            $("#Data").val(data);
            $("#formMain").submit();
        }
    </script>
}
